<?php
namespace app\admin\model;

use think\Config;
use think\Db;
use think\Loader;
use think\Model;
use traits\model\SoftDelete;
use houdunwang\Crypt;

class User extends model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';

    /**
     *  用户登录
     */
    public function login($username,$password)
    {
        $row = Db::name('user')->where('username',$username)->find();
        if(!$row){
            return 0;
        }else{
            if($row['password'] == encrypt($password)){
                unset($row['password']);
                return $row;
            }else{
                return 0;
            }
        }
    }

    public function getList(){
        $res = $this->alias('u')
            ->field('u.id,username,b.brand,team,u.status,g.title')
            ->join('tp_brand b','u.brand_id = b.id')
            ->join('tp_auth_group g','u.group_id = g.id')
            ->select()
            ->toArray();
        return $res;

    }

    public function deleteById($id)
    {
        $result = User::destroy($id);
        if ($result > 0) {
            return 1;
        }
    }

}
